var core = require('core');
var db = core.db;
var send = core.send;

var reg = function(req, res, next) {
    var body = req.body;
    var SEND;
    var user = db.schema.User;
    var query = {
        openid : body.openid
    };
    var update = {
        $set: {
            subscribe: false,
            subscribe_time: body.subscribe_time
        }
    };
    var options = {};
    user.update(query, update, options, function(err, doc){
        if(err){
            console.error(err.code);
            SEND = new send(100001);
        }else{
            SEND = new send(0);
            SEND.docs = doc;
        };
        res.send(SEND);
    });
};

module.exports = reg;
